// OSR b JVCS

package org.jvcs.server.core;

import org.jvcs.server.core.*;
import org.jvcs.common.*;
import org.jvcs.fmwk.*;

import java.io.*;
import java.net.*;
import java.util.*;

// Begin program
public class jvcsServer extends baseCS {
	public static int defPort = 2002;
	
	
	public static void main(String [] args) {
		osr.pl("Starting Server ...");
		
		// This is facing the user and accepting commands 
		// 1. load the props: global/common/local/this
		gini = osr.loadStdINI(G.GlobalINI);
		cini = osr.loadStdINI(G.CommonINI);
		lini = osr.loadStdINI(G.LocalINI);
		tini = osr.loadStdINI(G.ThisINI);
		
		PROG_NAME = gini.getProperty(G.PROGRAM_DISPLAY, G.NAME);
		
		// 2. parse the command line and understand
		CmdLine.parse(args);
		// 3. sort basic usage, version, help user queries
		helpBasicUsage();
		// 4. verbose on, print comments
		if (CmdLine.verboseFlag)
			helpDisplayDebug();
		// Start any threads which are admin
		
		// And finally service the client sockets
		// CLIENT-SERVICE
		ServerSocket serverSocket = null;
        boolean listening = true;

        try {
            serverSocket = new ServerSocket(defPort);
        } catch (Exception e) {
            osr.ee("Unable to bind port: "+defPort);
        }

       
		// finally
		try {
			while (listening)
				new JPServerThread(serverSocket.accept()).start();

			serverSocket.close();
		} catch (Exception e) {
			if (CmdLine.verboseFlag) osr.pl("Unable to close Server connections: "+e.toString());
            osr.ee("Unable to close Server.");
        }

	
	}

}